package com.jgdt.falsework.commonssm.common;

import com.jgdt.tools.decrypt.rest.Rest;

import java.io.Serializable;

/**
 * <p>
 *
 * </p>
 *
 * @author chang.zhou
 * @version $
 * @date Created in 2021/6/4 12:08
 */
public class RestBody<T> implements Rest<T>, Serializable {

    private int code;
    private String message;
    private T data;

    private RestBody(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    @Override
    public String getMessage() {
        return this.message;
    }

    @Override
    public T getData() {
        return this.data;
    }

    @Override
    public void setMessage(String message) {
        this.message = message;
    }

    @Override
    public void setData(T data) {
        this.data = data;
    }

    public static <T> RestBody<T> ok(T data){
        return new RestBody(200000,"操作成功",data);
    }

    public static Rest ok(){
        return new RestBody(200000,"操作成功",null);
    }

    public static Rest fail(int code,String message){
        return new RestBody(code,message,null);
    }

    public static <T> Rest<T> fail(int code,String message,T data){
        return new RestBody(code,message,data);
    }

    public static Rest fail(RestCode code){
        return new RestBody(code.getCode(),code.getMessage(),null);
    }

    public static <T> Rest<T> fail(RestCode code,T data){
        return new RestBody(code.getCode(),code.getMessage(),data);
    }
}
